package com.toidep.entities;

import org.json.JSONException;
import org.json.JSONObject;

import com.toidep.api.ParseJSON;
import com.toidep.config.Constants;

public class CommentEntity {

	private String id;
	private String username;
	private String time_after;
	private String comment;
	
	public CommentEntity() {
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getTime_after() {
		return time_after;
	}

	public void setTime_after(String time_after) {
		this.time_after = time_after;
	}

	public String getComment() {
		if (comment.charAt(comment.length()-1) == '\n') {
			return comment.substring(0, comment.length()-1);
		}
		return comment;
	}

	public void setComment(String comment) {
		this.comment = comment;
	}

	public void setInfo(JSONObject jsonObject) {
		this.id = ParseJSON.getStringValue(jsonObject, Constants.PARAM_RESPONSE_ID);
		this.time_after = ParseJSON.getStringValue(jsonObject, Constants.PARAM_RESPONSE_TIME_AFTER);
		this.comment = ParseJSON.getStringValue(jsonObject, Constants.PARAM_RESPONSE_COMMENT);
		
		try {
			JSONObject userComment = jsonObject.getJSONObject(Constants.PARAM_RESPONSE_USER_COMMENT);
			if (userComment != null)
				this.username = ParseJSON.getStringValue(userComment, Constants.PARAM_RESPONSE_USER_NAME);
		} catch (JSONException e) {
			e.printStackTrace();
		}
	}
	
}
